home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14439
/
14439.xpi
/
chrome
/
tabber.jar
/
content
/
tklib.js
< prev
Wrap
Text File
|
2009-10-22
|
5KB
|
137 lines
/*
Protected Tabs and Open Tabs from Bookmarks and History
Reference: Tab Kit by John Mellor
Latest revisions by Frank Yan - 2009.10.05
<license>
Tab Kit - http://jomel.me.uk/software/firefox/tabkit/
Copyright (c) 2007 John Mellor
This Firefox extension, Tab Kit, is free software; you can
redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your
option) any later version.
Tab Kit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
</license>
*/
// const Cc = Components.classes, Ci = Components.interfaces;
if(typeof gPrefService == "undefined" || !gPrefService)
gPrefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var tkLib = new function _tkLib() {
const tk = this;
this.addMethodHook = function(hook) {
try {
if(hook[1])
eval(hook[1] + "=" + hook[0]);
var code = eval(hook[0] + ".toString()");
for(var i = 2; i < hook.length; ) {
var newCode = code.replace(hook[i++], hook[i++]);
if(newCode == code) {
// method hook had no effect
}
else code = newCode;
}
eval(hook[0] + "=" + code);
}
catch(ex) {
// method hook failed
}
};
this.prependMethodCode = function(methodname, codestring) {
tk.addMethodHook([methodname, null, '{', '{' + codestring]);
};
this.beep = function() {
Cc["@mozilla.org/sound;1"].getService(Ci.nsISound).beep();
};
this.warnAboutClosingProtectedTabs = function(numProtected) {
window.focus();
var strings = document.getElementById("bundle_tabber");
var _ps = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var flags = _ps.BUTTON_POS_0 * _ps.BUTTON_TITLE_IS_STRING
+ _ps.BUTTON_POS_1 * _ps.BUTTON_TITLE_CANCEL
+ _ps.BUTTON_POS_2 * _ps.BUTTON_TITLE_IS_STRING;
var _tabs = gBrowser.mTabs;
var button = _ps.confirmEx(
window, //aParent
gBrowser.mStringBundle.getString("tabs.closeWarningTitle"), //aDialogTitle
strings.getFormattedString("close_warning_protected_tabs", [ _tabs.length, numProtected ]), //aText
flags, // aButtonFlags
strings.getString("close_all_tabs"), //aButton0Title
null, //aButton1Title // Cancel has to be button 1 due to Bug 345067 ΓÇô confirmEx always returns 1 when user closes dialog window using X button in titlebar
strings.getString("close_unprotected_tabs"), //aButton2Title
null, //aCheckMsg
{} //aCheckState
);
if(button == 0) { // Close all tabs
return true;
}
else if(button == 2) { // Close unprotected tabs
for (var i = _tabs.length - 1; i >= 0; --i)
if(_tabs[i].getAttribute("protected") != "true")
gBrowser.removeTab(_tabs[i]);
return false;
}
else { // Cancel
return false;
}
};
};
function tabberwockyOpenPlacesInTab() {
tkLib.addMethodHook([
'PlacesUIUtils.openNodeWithEvent',
null,
'this.openNodeIn(aNode, whereToOpenLink(aEvent));',
'this.openNodeIn(aNode, whereToOpenLink(aEvent), aEvent);'
]);
tkLib.addMethodHook([
'PlacesUIUtils.openNodeIn',
null,
'openUILinkIn(aNode.uri, aWhere);',
'if(arguments.length == 3 && gPrefService.getBoolPref("tabberwocky.opentabsfromplaces")) { \
if(aWhere == "tab" || /^\\s*javascript:/.test(aNode.uri)) { \
aWhere = "current"; \
} \
else { \
var w = getTopWin(); \
var browser = w ? w.getBrowser().mCurrentTab.linkedBrowser : w; \
if(aWhere == "current"\
&& (!browser \
|| browser.webNavigation.currentURI.spec != "about:blank" \
|| browser.webProgress.isLoadingDocument)) \
{ \
aWhere = "tab"; \
} \
} \
} \
$&'
]);
document.getElementById('placesContext').addEventListener('popupshowing', function() {
if(gPrefService.getBoolPref("tabberwocky.opentabsfromplaces")) {
document.getElementById('placesContext_open').removeAttribute('default');
document.getElementById('placesContext_open:newtab').setAttribute('default', true);
}
else {
document.getElementById('placesContext_open:newtab').removeAttribute('default');
document.getElementById('placesContext_open').setAttribute('default', true);
}
}, false);
}
window.addEventListener("load", tabberwockyOpenPlacesInTab, false);